import LoginRoute from "/@ts/router/routes/login";
import { ROOT_ADMIN_PAGE_NAME, ROOT_PAGE_NAME } from "/@ts/router/constant";

import { AppRouteModule } from "/@ts/router/types";
import { useRouteStructure } from "/@ts/hooks/route";
// const modules = import.meta.glob('./modules/**/*.ts');
const modules = import.meta.glob("/src/router/routes/modules/*.ts", {
  eager: true,
});
const RouteModuleList: AppRouteModule[] = [];
Object.keys(modules).forEach((key) => {
  const mod = modules[key].default || {};
  const modList = Array.isArray(mod) ? [...mod] : [mod];
  RouteModuleList.push(...modList);
});
export const RouteList = RouteModuleList; //没处理菜单的数据

export const MenuRouter = useRouteStructure(RouteModuleList); //处理后的菜单数据
const root: AppRouteModule[] = [
  {
    path: "/",
    // name: ROOT_PAGE_NAME,
    // meta: {
    //   title: "首页",
    // },
    component: () => import("/@/layouts/index.vue"),
    redirect: "workbench",
    children: [
      {
        path: "workbench",
        name: "dashboardWorkbench",

        meta: {
          title: "工作台",
        },
        component: () => import("/@/views/dashboard/workbench/workbench.vue"),
      },
    ],
  },
  {
    path: "/",
    // name: ROOT_PAGE_NAME,
    // meta: {
    //   title: "首页",
    // },
    component: () => import("/@/layouts/index.vue"),
    children: [
      {
        path: "analysis",
        name: "dashboardAnalysis",

        meta: {
          title: "分析页",
        },
        query: {},
        component: () => import("/@/views/dashboard/analysis/analysis.vue"),
      },
    ],
  },
];
const root2: AppRouteModule = {
  path: "/adminEdit",
  name: ROOT_ADMIN_PAGE_NAME,
  hidden: true,
  meta: {
    title: "后台设置",
  },
  component: () => import("/@/layouts/index2.vue"),
};
export const FilterRouterArr = (): Array<string> => {
  let data: any = MenuRouter.concat(LoginRoute);
  return data.map((res: any) => res.name);
};
// RouteModuleList.push(root)
export const basicRoutes: AppRouteModule[] = [
  root2,
  ...root,
  ...LoginRoute,
  ...RouteList,
];
